#include "plant.h"
#include"bullet.h"
#include"sun.h"

Plant::Plant(int xx,int yy,int hpmax,int ttype)
    :Object(xx,yy,hpmax,ttype)
{
    setZValue(5);
}




void Plant::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){

    if(walkmovie!=nullptr){
        painter->drawImage(boundingRect(),walkmovie->currentImage());
    }
    if(deadmovie!=nullptr){
        painter->drawImage(boundingRect(),deadmovie->currentImage());
    }
}
bool Plant::collidesWithItem(const QGraphicsItem *other, Qt::ItemSelectionMode mode) const{
    return other->y()== y()&&other->x()>x();
}
QRectF Plant::boundingRect() const{
    return QRectF(-35,-35,70,70);
}


SunFlower::SunFlower(int xx,int yy)
    :Plant(xx,yy,Hp_SunFlower,SunFlower_t)
{
}

void SunFlower::advance(int phase){
    if(phase==0){//预备更新
        CheckAndRemove();
        SetWalkMovie(":/resource/SunFlower.gif");
        Attack(t);
    }
    else{
        this->QGraphicsItem::update();
    }
}

//太阳花产生阳光
void SunFlower::Attack(int t){
    if(t%SunFlower_Sungap==0){
        Sun* s=new Sun(x()+10,y()+20);
        scene()->addItem(s);
    }
}